import React, { Component } from 'react';
import Taro from '@tarojs/taro';
import {View, Image, Block} from '@tarojs/components'
import {connect} from 'react-redux'
import './float-redbag.scss'

type PageStateProps = {
  redbag?: { isShow: number; image: string }
}

type IProps = PageStateProps

interface FloatRedbag {
  props: IProps
}

@connect(({redbag}) => ({
  redbag
}), () => ({}))

class FloatRedbag extends Component {

  render() {
    const redbag: any = this.props.redbag
    return (
      <Block>
        {redbag.isShow == 1 && <View className='redbag' onClick={() => {
          let mpkey = ''
          const uInfo = Taro.getStorageSync('user') || ''
          if (uInfo && uInfo.mpkey && uInfo.mpkey !== 'undefined') {
            mpkey = uInfo.mpkey
          }
          Taro.navigateTo({url: '/common/redbag/redbag' + '?mpkey=' + mpkey})
        }
        }
        >
          <Image className='img' src={redbag.image} mode='widthFix' />
        </View>}
      </Block>
    )
  }
}

export default FloatRedbag
